package com.example.member.vm

import com.example.common.view.vm.BaseViewModel
import com.example.member.api.MemberApiService
import com.example.member.entity.MemberEntity
import com.example.member.model.MemResultData
import com.example.member.model.MemberRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MemViewModel  @Inject constructor(private val apiService: MemberApiService): BaseViewModel<MemberRepository, MemberEntity>() {
    fun getMember(userId:Int) {
        mViewModelScope.launch(mDispatcher) {
            try {
                val result = apiService.getMember(userId)
                mSuccessLiveData.postValue(result)
            } catch (e: Exception) {
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
    fun getMemberUp(newMembershipLevel:String,userId:Int) {
        mViewModelScope.launch(mDispatcher) {
            try {
                val result = apiService.getMemberUp(newMembershipLevel,userId)
                mSuccessLiveData.postValue(result)
            } catch (e: Exception) {
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}